<template>
  <div class="stream-container">
    <!-- 页面标题 -->
    <header class="header">
      <h1>短视频数据监控</h1>
      <p>实时统计当前状态</p>
    </header>

    <!-- 主内容区 -->
    <main class="content">
      <!-- 数据概览卡片 -->
      <div class="stats-card">
        <h2>实时数据概览</h2>
        <div class="stats-grid">
          <div class="stat-item">
            <div class="stat-value">{{videoStats.id}}</div>
            <div class="stat-label">id</div>
          </div>
          <div class="stat-item">
            <div class="stat-value">{{videoStats.vid}}</div>
            <div class="stat-label">视频id</div>
          </div>
          <div class="stat-item">
            <div class="stat-value">{{ videoStats.views }}</div>
            <div class="stat-label">视频观看次数</div>
          </div>
          <div class="stat-item">
            <div class="stat-value">其他</div>
            <div class="stat-label">无</div>
          </div>
        </div>
      </div>

      <!-- 饼图组件 -->
      <div class="chart-card">
        <h2>视频推流情况</h2>
        <StatsPieChart />
      </div>
    </main>

    <!-- 页脚 -->
    <footer class="footer">
      <p>@ 2025 短视频平台</p>
    </footer>
  </div>
</template>

<script>

// 导入饼图组件
import PieChart from './PieChart.vue'
import SimpleSidebar from "@/views/chart/SimpleSidebar.vue";
import Service from '@/router/interceptor.js'
export default {
  name: 'App',
  data() {
    return {
      videoStats: {
        id: '',
        vid: '',
        views: 0,
        total: 0
      }
    }
  },
  async created() {
    const videoId = this.$route.params.videoId;
    console.log(videoId)
    try {
      const response = await Service.get('/api/videoRank/getVideoRankById', { params: { id: videoId } });
      console.log(response.data)
      this.videoStats = {
        id: response.data.id,
        vid: response.data.vid,
        views: response.data.views,
        total: response.data.total
      };
    } catch (error) {
      console.error('获取数据失败:', error);
    }
  },
  components: {
    SimpleSidebar,
    StatsPieChart: PieChart
  }
}
</script>

<style scoped>
/* 主容器样式 */
.stream-container {
  min-height: 100vh;
  width: 100vmax;/* 使用视口宽度 */
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  font-family: 'Arial', sans-serif;
}

/* 头部样式 */
.header {
  text-align: center;
  padding: 2rem;
  background: linear-gradient(to right, #d9efff, #764ba2);
  color: white;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.header h1 {
  margin: 0;
  font-size: 2.5rem;
}

.header p {
  margin: 0.5rem 0 0;
  opacity: 0.9;
}

/* 内容区域样式 */
.content {
  flex: 1;
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 768px) {
  .content {
    grid-template-columns: 1fr 1fr; /* 单列布局 */
    padding: 1rem;             /* 减少内边距 */
  }
}

/* 卡片通用样式 */
.stats-card,
.chart-card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.stats-card h2,
.chart-card h2 {
  margin-top: 0;
  color: #4a5568;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.75rem;
}

/* 数据网格样式 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.stat-item {
  text-align: center;
  padding: 1rem;
  background: #f8fafc;
  border-radius: 8px;
}

.stat-value {
  font-size: 2rem;
  font-weight: bold;
  color: #4a5568;
}

.stat-label {
  font-size: 0.9rem;
  color: #718096;
  margin-top: 0.5rem;
}

/* 页脚样式 */
.footer {
  text-align: center;
  padding: 1.5rem;
  background: #4a5568;
  color: white;
}
</style>